// 自定义dialog
import 'package:flutter/material.dart';

class AdbConnectDialog extends Dialog {
  String title;
  String content;
  final TextEditingController _controllerIp = TextEditingController();
  Function()? onClosed;
  Function(String malv)? onConfirm;

  AdbConnectDialog(
      {Key? key,
      required this.title,
      required this.onClosed,
      required this.onConfirm,
      this.content = ""})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    _controllerIp.value = const TextEditingValue(text: "");
    return Material(
      type: MaterialType.transparency,
      child: Center(
          child: ClipRRect(
        borderRadius: BorderRadius.circular(10),
        child: Container(
          height: 300,
          width: 300,
          padding: const EdgeInsets.all(10),
          color: Colors.white,
          child: Column(
            children: <Widget>[
              Container(
                height: 245,
                padding: const EdgeInsets.all(10),
                width: MediaQuery.of(context).size.width,
                child: Column(
                  children: [
                    Container(margin: const EdgeInsets.fromLTRB(0, 0, 0, 0),child: TextField(
                        keyboardType: TextInputType.text,
                        controller: _controllerIp,
                        decoration: const InputDecoration(
                          labelText: 'IP地址',
                          border: OutlineInputBorder(),
                        )),)
                  ],
                ),
              ),
              Row(
                children: [
                  Expanded(
                      flex: 1,
                      child: TextButton(
                        onPressed: () => {onClosed?.call()},
                        child: Text("取消"),
                      )),
                  Expanded(
                      flex: 1,
                      child: TextButton(
                        onPressed: () => {
                          onConfirm?.call(_controllerIp.value.text)
                        },
                        child: Text("确认"),
                      ))
                ],
              )
            ],
          ),
        ),
      )),
    );
  }
}
